import matplotlib.pyplot as plt
import numpy as np


def myfunc(x):
    if(0<=x<1):
        return 2*x - 2
    else:
        return 2*x
vfunc = np.vectorize(myfunc)
def getRandomPointFromCircle(x, y, r, num, flag='xiao'):
    if(flag == "xiao"):
        xmin, xmax = x-r, x+r
        xvector = np.random.rand(num, 1)*(xmax-xmin) + xmin
        ymaxvector = np.sqrt(r*r - (xvector - x)*(xvector-x)) + y
        yminvector = -np.sqrt(r*r - (xvector - x)*(xvector-x)) + y
        yvector = np.random.rand(num, 1)*(ymaxvector - yminvector) + yminvector
        return np.hstack((xvector, yvector))
    else:
        xmin, xmax = x-r, x+r
        xvector = np.random.rand(num, 1)*(xmax-xmin) + xmin
        yvector = vfunc(xvector)
        plt.scatter(xvector, yvector, edgecolors='red')
        return np.hstack((xvector, yvector))

one = getRandomPointFromCircle(1, 1, 1, 100)
two = getRandomPointFromCircle(1, 1, 1, 100, flag='da')

plt.scatter(one[:,0], one[:,1], edgecolors='red')
plt.scatter(two[:,0], two[:,1])

plt.show()
